import { MetaDefenderAddress } from './contactAddress'

let web3Data = {
  namespaced: true,
  state() {
    return {
      policyArr: [],
      certificateArr: [],
      medalArr: [],
      poolAddressArr: {
        [MetaDefenderAddress.toLowerCase()]: {
          Name: 'compoundCOMPOUNDCompound',
          Protected: 'Compound V3',
          NetWork: 'Ethereum',
          ProtectionType: 'Contract Safety',
          Token: 'USDT',
        },
      },
      reward: '',
      globalViewerData: [],
      globalViewerDataLoading: true,
      epochTime: '',
      withdrawAmount: '-',
    }
  },
  mutations: {
    updatePolicyArr(state, policyArrFromAxios) {
      state.policyArr = policyArrFromAxios
    },
    updateMedalArr(state, medalArrFromAxios) {
      state.medalArr = medalArrFromAxios
    },
    updateCertificateArr(state, certificateArrFromAxios) {
      state.certificateArr = certificateArrFromAxios
    },
    updateReward(state, rewardFromAxios) {
      state.reward = rewardFromAxios
    },
    updateGlobalViewerData(state, globalViewerData) {
      state.globalViewerData = globalViewerData
      state.globalViewerDataLoading = false
    },
    updateEpochTime(state, epochTime) {
      state.epochTime = parseInt(epochTime.toHexString(), 16) * 1000
    },
    updateWithdrawableAmount(state, withdrawAmount) {
      state.withdrawAmount = withdrawAmount
    },
  },
  actions: {
    doupdatePolicyArr(context, policyArrFromAxios) {
      context.commit('updatePolicyArr', policyArrFromAxios)
    },
    doupdateMedalArr(context, medalArrFromAxios) {
      context.commit('updateMedalArr', medalArrFromAxios)
    },
    doupdateCertificateArr(context, certificateArrFromAxios) {
      context.commit('updateCertificateArr', certificateArrFromAxios)
    },
    doupdateReward(context, rewardFromAxios) {
      context.commit('updateReward', rewardFromAxios)
    },
    doupdateGlobalViewerData(context, globalViewerData) {
      context.commit('updateGlobalViewerData', globalViewerData)
    },
    doupdateEpochTime(context, epochTime) {
      context.commit('updateEpochTime', epochTime)
    },
    doupdateWithdrawableAmount(context, withdrawAmount) {
      context.commit('updateWithdrawableAmount', withdrawAmount)
    },
  },
}

export default web3Data
